package com.chouren.goandroid.animate;

import android.content.Context;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.view.animation.Animation.AnimationListener;

public class Animations {
	
	public static Animation animScale(Context context, float toX, float toY) {
		Animation animation = new ScaleAnimation(1.0f, toX, 1.0f, toY,
				Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
				0.5f);
		animation.setInterpolator(context,
				android.R.anim.accelerate_decelerate_interpolator);
		animation.setDuration(200);
		animation.setFillAfter(false);
		return animation;

	}

	public static Animation animRotate(float toDegrees, float pivotXValue,
			float pivotYValue) {
		final Animation animation = new RotateAnimation(0, toDegrees,
				Animation.RELATIVE_TO_SELF, pivotXValue,
				Animation.RELATIVE_TO_SELF, pivotYValue);
		animation.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {

			}

			@Override
			public void onAnimationRepeat(Animation animation) {

			}

			@Override
			public void onAnimationEnd(Animation animation) {
				animation.setFillAfter(true);
			}
		});
		return animation;
	}

	/**
	 * 移动动画，用于实现弹出效果
	 * 
	 * @param fromX
	 *            开始位置
	 * @param toX
	 *            结束位置
	 * @param fromY
	 *            开始位置
	 * @param toY
	 *            结束位置
	 * @param durationMillis
	 *            动画执行时间
	 * @return
	 */
	public static Animation animTranslate(float fromX, float toX, float fromY,
			float toY, long durationMillis) {
		Animation animation = new TranslateAnimation(fromX, toX, fromY, toY);
		animation.setDuration(durationMillis);
		return animation;
	}
}
